package com.logic.saas.util;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;

public class SysCache {
	private Logger logger = Logger.getLogger(SysCache.class);
	private Map<String, Object> sysconfig;
	
	private SysCache() {
		logger.debug("====== new cache instance created ======");
	}

	private static SysCache instance = null;

	public static synchronized SysCache getInstance() {
		if (instance == null) {
			instance = new SysCache();
		}
		return instance;
	}
	
	public String getSysConfig(String key){
		String result = null;
		if(key == null){
			return null;
		}
		if(sysconfig == null){
			sysconfig = new HashMap<String, Object>();
		}
		if(sysconfig.containsKey(key.toLowerCase())){
			result = sysconfig.get(key.toLowerCase()).toString();
		}else	if(SysConfig.getItem(key) != null){
			result = SysConfig.getItem(key);
			sysconfig.put(key.toLowerCase(), result);
		}else{
			//error find SysConfig
			logger.error("无法找到系统配置："+key.toLowerCase());
		}
		return result;
	}

	public Map<String, Object> getSysconfig() {
		return sysconfig;
	}

	public void setSysconfig(Map<String, Object> sysconfig) {
		this.sysconfig = sysconfig;
	}

	
}